<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/30
 * Time: 14:26
 */

include_once 'redis.php';

// 获取请求数据
$param = $_POST;

// 验证
if (empty($param['username'])) notice('账号不能为空');
if (empty($param['password'])) notice('密码不能为空');

// 获取uid
$uid = $redis->get("username:{$param['username']}");
if (empty($uid)) notice('用户不存在');

// 获取用户信息
$userInfo = $redis->hGetAll("user:{$uid}");
if (empty($userInfo)) notice('获取用户信息失败');

// 比对密码
if (md5($param['password']) != $userInfo['password']) notice('密码错误');

unset($userInfo['password']);//注释密码信息
$redis->hMset($sessionId, $userInfo);// 保存用户信息到redis_session
$redis->expire($sessionId, $redisSessionTime);// 设置redis_session时效

notice('登录成功', 'main.php');
?>